﻿CREATE PROCEDURE [dbo].[UserAccount_Create]
	@FirstName nvarchar(50),
	@LastName nvarchar(50),
	@Email nvarchar(50),
	@CompanyId int,
	@Phone nvarchar(20),
	@Info nvarchar(max),
	@UserRoleId int,
	@Pass nvarchar(50)
AS
BEGIN
	if exists(SELECT NULL from UserAccount where Email = @Email)
	begin
		select 7 as [Status], 0 as UserAccoundId -- DuplicateEmail = 7
		return 
	end

	if exists(SELECT NULL from UserAccount where LastName = @LastName and FirstName = @FirstName)
	begin
		select 6 as [Status], 0 as UserAccoundId -- DuplicateUserName = 6
		return 
	end

	insert into UserAccount (FirstName, LastName, Email, CompanyId, Phone, Info, UserRoleId, Pass)
	values (@FirstName, @LastName, @Email, @CompanyId, @Phone, @Info, @UserRoleId, @Pass)

	select 0 as [Status], SCOPE_IDENTITY() as UserAccoundId -- Success = 0
END